// ***************************************************************************
// Caution: modifying this file will affect the integrity of the application.
// ***************************************************************************
// Copyright © 1995-2007, Camstar Systems, Inc. All Rights Reserved.
// This file is in use with the PickList controls.

var mkStatusMessageCtrlId = "StatusMessage";

var pickLists = [];

// Displays status message either in the status frame or status control on a form 
// Pops up an alert message box if no status frame or control found.
function DisplayMessage(message, isSuccess)
{
    // Write message to the status frame
    if (parent.frames.WriteMessage != null)
    {
        parent.frames.WriteMessage(message, isSuccess);
    }
    else 
    // Write message to the status control on the current form
    if (document.getElementById(mkStatusMessageCtrlId) != null)
    {
        var statusCtrl = document.getElementById(mkStatusMessageCtrlId);

        var spans = document.getElementsByTagName(top.TagSpan);
        if (spans != null && spans.length > 0)
        {
            spans[spans.length - 1].innerText = message;
            if(isSuccess)
                spans[spans.length - 1].style.color = top.ColorBlack;
            else
                spans[spans.length - 1].style.color = top.ColorRed;
        }
    }
    // Display message box with the text message
    else
    {
        alert(message);
    }
}

function getPickListByViewCtrlId(viewCtrlId)
{
    for(var pickListId in pickLists)
    {
        if(pickLists[pickListId].viewCtrlId == viewCtrlId)
            return pickLists[pickListId];
    }
    return null;
}

function getPickListByChildCtrlId(childCtrlId)
{
    for(var pickList in pickLists)
    {
        if(pickList.viewCtrlId == childCtrlId || pickList.filterCtrlId == childCtrlId ||
            pickList.pagerCtrlId == childCtrlId)
            return pickList;
    }
    return null;
}

function getPickListById(pickListId)
{
    return pickLists[pickListId];
}

function PickListControl(_insiteCtrlId, _viewCtrlId, _filterCtrlId, _pagerCtrlId, _needPostBack, _typeAhead, _dependentControls, _viewCtrlConstr)
{
    this.insiteCtrlId = _insiteCtrlId;
    this.viewCtrlId = _viewCtrlId;
    this.filterCtrlId = _filterCtrlId;
    this.pagerCtrlId = _pagerCtrlId;
    this.needPostBack = _needPostBack;
    this.typeAhead = _typeAhead;
    this.dependentControls = _dependentControls;
    this.viewCtrl = new _viewCtrlConstr(this);
    this._iframe = null;
    this.zIndex = 0;

    this.InitIframe = function()
    {
        this._iframe = document.createElement('iframe');
	this._iframe.height = '0px';
	this._iframe.width = '0px';
        this._iframe.src = 'javascript:new String("<html></html>")';
        this._iframe.style.visibility = 'hidden';
        this._iframe.style.display='none';
        this._iframe.style.position = 'absolute';
        this._iframe.id = this.insiteCtrlId + '_Frame';
    }
    this.ShowIframe = function()
    {
        this.InitIframe();
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        this._iframe.style.top = div.offsetTop;
        this._iframe.style.left = div.offsetLeft;
        this._iframe.style.height = div.offsetHeight;
        this._iframe.style.width = div.offsetWidth;
        this._iframe.style.zIndex = 1000;
        this._iframe.style.visibility = 'visible';
        this._iframe.style.display='';
        document.forms[0].appendChild(this._iframe);
    }    
      
    this.HideIframe = function()
    {
        this._iframe.style.visibility = 'hidden';
        this._iframe.style.display='none';
        document.forms[0].removeChild(this._iframe);
        this._iframe = null;
    }    

    this.CorrectIframe = function()
    {
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        if (this._iframe != null)
            this._iframe.style.height = div.offsetHeight;
    }
    this.lasttype = '';
    this.typing = false;
    this.tabbing = false;
    this.OnTypeAhead = function()
    {
        if(event.keyCode == '9' || event.keyCode == '40')
            return;

        var edit = document.getElementById(this.insiteCtrlId + "_Edit");
        var filterCtrl = document.getElementById(this.filterCtrlId + "_Fltc");
        
        if(filterCtrl.value == edit.value)
            return;

        var handler = edit.onchange;
        edit.onchange = null;
        this.typing = true;
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        if (div != null && div.style.display == "none")
    {
            document.getElementById(this.insiteCtrlId + "_Stat").checked = true;
            this.ClickOpenClose();
    }

        filterCtrl.value = edit.value;
        this.FilterClick();
        edit.focus();
        this.typing = false;
        edit.onchange = handler;
    }
    this.OnControlTypeAhead = function()
    {
        var edit = document.getElementById(this.insiteCtrlId + "_Edit");
        if(event.keyCode == '9')
        {
            var div = document.getElementById(this.insiteCtrlId + "_Panl");
            if (div != null && div.style.display == "")
            {
                this.tabbing = true;
                this.Focus();
                return false;
            }
        }
    }
    this.prevActive = null;
    this.updateInProgress = '';
    this.nextOrPrev = '';
    this.keyEnter = false;
    this.onKeyDown = null;
    this.onKeyUp = null;
    this.onDeactivateHandler = null;

    this.InitTabs = function(elem)
    {
        var ev = this;
        this.onKeyDown = function()
        {
            ev.nextOrPrev = '';
            if(event.keyCode == '9')
            {
                if(event.shiftKey)
                    ev.nextOrPrev = 'Prev';
                else
                    ev.nextOrPrev = 'Next';
            }
        };
        this.onKeyUp = function()
        {
            ev.nextOrPrev = '';
        };
        elem.attachEvent('onkeydown', this.onKeyDown);
        elem.attachEvent('onkeyup', this.onKeyUp);
    }
    this.ResetTabs = function(elem)
    {
        elem.detachEvent('onkeydown', this.onKeyDown);
        elem.detachEvent('onkeyup', this.onKeyUp);
    }
    this.OnDeactivate = function()
    {
        var elem = event.toElement;
        var ctrl = document.getElementById(this.insiteCtrlId + "_Edit");
        var btn = document.getElementById(this.insiteCtrlId + "_Imbt");
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        var ev = this;
        var timeout = 200;


        if(this._iframe != null)
        {
            if(this._iframe.id == event.srcElement.id)
            {
                if(elem.attributes['gn'] != null && elem.attributes['gn'].value == this.viewCtrlId)
                {
                    elem.attachEvent('ondeactivate', function() { ev.OnDeactivate();});
                    this.InitTabs(elem);
                    if(elem.tabIndex != -1)
                        elem.focus();
                    elem.tabIndex = -1;
                }
                return;
            }
        }
        // Only for grid 
        if(event.srcElement.attributes['gn'] != null && event.srcElement.attributes['gn'].value == this.viewCtrlId)
        {
            this.ResetTabs(event.srcElement);
            if(this.nextOrPrev == 'Prev')
            {
                this.prevActive.focus();
                if(this.prevActive.id != (this.insiteCtrlId + "_Imbt"))
                    return;
            }
            if(this.nextOrPrev == 'Next')
            {
                ctrl.focus();
            }
        }
        var xelem = event.srcElement;
        var isinit = false;
        var xxelem = event.toElement;
        while(xxelem != null)
        {
            if(xxelem.id == ('T_' + this.viewCtrlId))
                isinit = true;
            xxelem = xxelem.parentElement;
        }
        while(xelem != null)
        {
            if(xelem.id == ('T_' + this.viewCtrlId))
            {
                this.ResetTabs(event.srcElement);
                if(!isinit)
                {
                    if(this.nextOrPrev == 'Prev')
                    {
                        this.prevActive.focus();
                        this.nextOrPrev = '';
                        if(this.prevActive.id != (this.insiteCtrlId + "_Imbt"))
                            return;
                    }
                    else if(this.nextOrPrev == 'Next' && event.srcElement.tabIndex != -1)
                    {
                        ctrl.focus();
                    }
                }
                event.srcElement.tabIndex = -1;
            }
            xelem = xelem.parentElement;
        }
        if(isinit)
        {
            this.InitTabs(event.toElement);
        }
        if(elem != null)
        {
            if(this._iframe != null)
            {
                if(this._iframe.id == elem.id)
                {
                    this._iframe.attachEvent('ondeactivate', function() { ev.OnDeactivate();} );
                    if(event.srcElement.id != this.viewCtrlId && event.srcElement.id != ('T_' + this.viewCtrlId))
                    {
                        this.prevActive = event.srcElement;
                        if(event.srcElement.id == (this.insiteCtrlId + "_Panl"))
                            this.prevActive = document.getElementById(this.insiteCtrlId + "_Imbt");
                        this.viewCtrl.Focus(false);
                        return;
                    }
                    else
                    {
                        ctrl.focus();
                    }
                }
                if(elem.id == ('T_' + this.viewCtrlId))
                {
                    this.prevActive = event.srcElement;
                }
            }
            if(elem.attributes['gn'] != null && elem.attributes['gn'].value == this.viewCtrlId)
            {
                elem.attachEvent('ondeactivate', function() { ev.OnDeactivate();});
                this.InitTabs(elem);
                if(elem.tabIndex != -1)
                    elem.focus();
                elem.tabIndex = -1;
                return;
            }
            
            if(event.srcElement.id == (this.filterCtrlId + '_Fltc') && elem.id == 'cancelSubmit')
            {
                var filterbtn = document.getElementById(this.filterCtrlId + "_Flic");
                filterbtn.click();
                setTimeout('document.getElementById("' + this.filterCtrlId + '_Flic").focus();', 100);
                return;
            }
            if(elem.id == (this.insiteCtrlId + '_Firstfocus'))
            {
                var imbt = document.getElementById(this.insiteCtrlId + "_Imbt");
                imbt.focus();
            }
        
            while(elem != null)
            {
                if(elem.id == div.id)
                    return;
                elem = elem.parentElement;
            }
        }
        else
            timeout = 1;
        if(this.tabbing)
        {
            document.getElementById(this.insiteCtrlId + "_Edit").fireEvent("onchange");
            this.tabbing = false;
        }
        if(this.typing || this.tabbing)
            return;
        
        var firstfocus = document.getElementById(this.insiteCtrlId + "_Firstfocus");
        if(firstfocus != null)
            document.forms[0].removeChild(firstfocus);
        setTimeout('getPickListById("' + this.insiteCtrlId + '").Deactivate();', timeout);
    }
    this.Deactivate = function(elemId)
    {
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        if (div != null && div.style.display == "")
        {
                    this.Close();
        }
    }
    this.PreClickOpenClose = function () {
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        var edit = document.getElementById(this.insiteCtrlId + "_Edit");
        var ctrl = document.getElementById(this.insiteCtrlId);
        var tempControl = edit.offsetParent;
        var top = edit.offsetHeight;
        while (tempControl != null) {
            top += tempControl.offsetTop;
            if (tempControl.tagName != 'BODY')
                top -= tempControl.scrollTop;
            tempControl = tempControl.offsetParent;
        }
        tempControl = edit;
        var left = 0;
        if (edit.clientLeft)
            left = edit.clientLeft;
        while (tempControl.tagName != 'BODY' && tempControl.offsetParent != null)
        {
            left += tempControl.offsetLeft;
            left -= tempControl.scrollLeft;
            tempControl = tempControl.offsetParent;

        }
        div.style.top = (top + 1) + 'px';
        div.style.left = (left - 1) + 'px';

        var ctrlTds = div.getElementsByTagName("td");
        for (var i = 0; i < ctrlTds.length; i++) {
            ctrlTds[i].setAttribute("vAlign", "top");

        }

        var firstfocus = document.createElement('button');
        firstfocus.style.top = top + 'px';
        firstfocus.style.left = left + 'px';
        firstfocus.style.height = '0px';
        firstfocus.style.width = '0px';
        firstfocus.style.position = 'absolute';
        firstfocus.id = this.insiteCtrlId + '_Firstfocus';
        document.forms[0].appendChild(firstfocus);
        document.forms[0].appendChild(div);
        firstfocus.focus();
        var ev = this;
        var tempControl = document.getElementById(this.insiteCtrlId);
        while (tempControl != null) {
            if (tempControl.tagName == 'DIV')
                tempControl.attachEvent('onscroll', function () { ev.Close(); });
            tempControl = tempControl.offsetParent;
        }
    }
    this.Close = function()
    {
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        if (div != null && div.style.display == "")
        {
            this.HideIframe();
            div.style.display = "none";
        }
    }
    this.Focus = function()
    {
        var pager = document.getElementById(this.pagerCtrlId);
        var filter = document.getElementById(this.filterCtrlId);
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        if(div != null && div.style.display == "none")
            return;
        if(pager != null && pager.style.display != 'none')
        {
            var next = document.getElementById(this.pagerCtrlId + '_Next');
            if(next.disabled)
                next = document.getElementById(this.pagerCtrlId + '_Prev');
            next.focus();
        }
        else if(filter != null && filter.style.display != 'none')
        {
            document.getElementById(this.filterCtrlId + "_Fltc").focus();
        }
        else
        {
            div.focus();
            this.viewCtrl.Focus(false);
            this.prevActive = document.getElementById(this.insiteCtrlId + "_Imbt");
        }
    }
    this.ClickOpenClose = function()
    {
        var div = document.getElementById(this.insiteCtrlId + "_Panl");
        var ev = this;
        if(this.typeAhead)
        {
            var edit = document.getElementById(this.insiteCtrlId + "_Edit");
            edit.attachEvent('ondeactivate', function()
            {
                if(div.style.display == '' && !(ev.tabbing || ev.typing))
                    edit.focus();
            });
            var filter = document.getElementById(this.filterCtrlId);
            filter.style.display = 'none';
        }
        if (div != null && div.style.display == "none")
        {
            this.PreClickOpenClose();
            div.style.display = "";
            this.ShowIframe();
            this.Focus();

            var load = true;
            var state = document.getElementById(this.insiteCtrlId + "_Stat");
            if (state != null)
            {
                if (state.checked == false)
                    state.checked = true;
                else
                    load = false;
            }
            
            if (load == true)
            {
                this.Load();
            }
            var parent = div.parentElement;
            while (parent != null && parent.id != mkUserFieldsDiv && parent.id != mkParametricDiv)
                parent = parent.parentElement;
            if (parent == null)
            {
                var bottomPos = div.offsetHeight + div.style.pixelTop;
                var tempControl = div.offsetParent;
                bottomPos -= tempControl.scrollTop;
                if ( bottomPos > document.body.offsetHeight )
                    div.scrollIntoView(false);    
            }
        }
        else
            this.Close();
        return this.needPostBack;
    }
    this.Load = function()
    {
        this.SetPagesCount(1);
        this.viewCtrl.Load();
    }

    this.FilterClick = function()
    {
        this.updateInProgress = 'Started';
        this.viewCtrl.Focus(true);
        document.getElementById(this.pagerCtrlId + "_Curp").value = 1;
        var res = this.viewCtrl.Filter();
        return this.needPostBack;
    }

    this.PagerClick = function(pageNumber)
    {
        this.updateInProgress = 'Started';
        this.viewCtrl.Focus(true);
        var currentPage = 1;
        var pagesCount = 1;

        var currentPageCtrl = document.getElementById(this.pagerCtrlId + "_Curp");
        var pagesCountCtrl = document.getElementById(this.pagerCtrlId + "_Pcnt");

        if (pagesCountCtrl != null)
        {
            pagesCount = parseInt(pagesCountCtrl.value);
            if (isNaN(pagesCount))
                pagesCount = 1;
        }
                
        if (currentPageCtrl != null)
        {
            var currentPage = parseInt(currentPageCtrl.value);
            if (isNaN(currentPage))
                currentPage = 1;
            
            switch (pageNumber)
            {
                case "First": 
                {
                    currentPage = 1; 
                    this.SetPagerButtonDisable('Prev');
                    break;
                }    
                case "Prev": 
                {
                    currentPage -= 1;
                    if (currentPage == 1)
                        this.SetPagerButtonDisable('Prev');
                    else
                        this.SetPagerButtonDisable('');
                    break;
                }
                case "Next": 
                {
                    currentPage += 1;
                    if (currentPage == pagesCount)
                        this.SetPagerButtonDisable('Next');
                    else
                        this.SetPagerButtonDisable('');
                    break;
                }
                case "Last": 
                {
                    currentPage = pagesCount; 
                    this.SetPagerButtonDisable('Next');
                    break;
                }
                default:
                {
                    currentPage = parseInt(pageNumber);
                    if (isNaN(currentPage))
                        currentPage = 1;
                }
            }
            
            currentPageCtrl.value = currentPage;
        }

        var res = this.viewCtrl.Page();
        return this.needPostBack;
    }

    this.Select = function(selectedId)    
    {
        if(this.keyEnter)
        {
            this.keyEnter = false;
            return;
        }
        var res = this.viewCtrl.Select(selectedId);
        if(!res)
            return;
        var ctrl = document.getElementById(this.insiteCtrlId + "_Edit");
        if(this.typeAhead)
        {
            var filterCtrl = document.getElementById(this.filterCtrlId + "_Fltc");
            filterCtrl.value = ctrl.value;
        }
        setTimeout('document.getElementById("' + this.insiteCtrlId + '_Edit").focus();', 100);
        return this.needPostBack;
    }
    
    this.SetPagesCount = function(pagesCount)
    {
        var pagesCountCtrl = document.getElementById(this.pagerCtrlId + "_Pcnt");
        var currentPageCtrl = document.getElementById(this.pagerCtrlId + "_Curp");
        var pagesDisableCtrl = document.getElementById(this.pagerCtrlId + "_Dis");
        var pages = parseInt(pagesCount);
        if(pages == 1)
        {
            document.getElementById(this.pagerCtrlId).style.display = 'none';
            pagesDisableCtrl.value = 'All';
            this.CorrectIframe();
            this.Focus();
        }
        else
        {
            document.getElementById(this.pagerCtrlId).style.display = '';
            this.SetPagerButtonDisable('Prev');
            this.CorrectIframe();
        }
        pagesCountCtrl.value = pages;
        currentPageCtrl.value = 1;
    }
    
    this.SetPagerButtonDisable = function(direction)
    {
        this.SetPagerPicture = function(pagerButton)
        {
            pagerButton.src = pagerButton.src.replace(/Gray.gif/g, '.gif');
            if(pagerButton.disabled)
                pagerButton.src = pagerButton.src.replace(/.gif/g, 'Gray.gif');
        }
        var pagerButton = null;
        pagerButton = document.getElementById(this.pagerCtrlId + '_First');
        pagerButton.disabled = false;
        this.SetPagerPicture(pagerButton);
        pagerButton = document.getElementById(this.pagerCtrlId + '_Prev');
        pagerButton.disabled = false;
        this.SetPagerPicture(pagerButton);
        pagerButton = document.getElementById(this.pagerCtrlId + '_Next');
        pagerButton.disabled = false;
                this.SetPagerPicture(pagerButton);
        pagerButton = document.getElementById(this.pagerCtrlId + '_Last');
        pagerButton.disabled = false;
                this.SetPagerPicture(pagerButton);
        var pagesDisableCtrl = document.getElementById(this.pagerCtrlId + "_Dis");
        pagesDisableCtrl.value = '';
        switch (direction)
        {
            case 'Prev':
            {
                pagerButton = document.getElementById(this.pagerCtrlId + '_Prev');
                pagerButton.disabled = true;
                this.SetPagerPicture(pagerButton);
                pagerButton = document.getElementById(this.pagerCtrlId + '_First');
                pagerButton.disabled = true;
                this.SetPagerPicture(pagerButton);
                pagesDisableCtrl.value = 'Prev';
                break;
            }
            case 'Next':
            {
                pagerButton = document.getElementById(this.pagerCtrlId + '_Next');
                pagerButton.disabled = true;
                this.SetPagerPicture(pagerButton);
                pagerButton = document.getElementById(this.pagerCtrlId + '_Last');
                pagerButton.disabled = true;
                this.SetPagerPicture(pagerButton);
                pagesDisableCtrl.value = 'Next';
                break;
            }
        }
    }
    
    this.ClearValue = function()
    {
        document.all[this.insiteCtrlId + "_Edit"].value = "";
        this.viewCtrl.ClearKey();
    }

    this.ReloadDependent = function()
    {
        if (this.dependentControls != null)
        {
            for (var i=0; i<this.dependentControls.length; i++)
            {
                var ctrlId = this.dependentControls[i];
                var div = document.getElementById(ctrlId + "_Panl");
                if (div != null)
                {
                    var dependentInSiteCtrl = getPickListById(ctrlId);
                    if (dependentInSiteCtrl != null)
                    {
                        dependentInSiteCtrl.ClearValue();
                        
                        if (div.style.display == "none")
                        {
                            var state = document.getElementById(ctrlId + "_Stat");
                            state.checked = false;
                        }
                        else
                        {
                            dependentInSiteCtrl.Load();
                        }
                    }
                    else
                    {
                        alert("Dependent control '" + ctrlId + "' not found on the form.");
                    }
                }
            }
        }
    }
    // End of PickList control client-side functions

    this.readyState = "complete";
}

function ViewControlBase(pickListCtrl)
{
    this.pickListControl = pickListCtrl;
    this.Load = function()
    {
    }
    this.Filter = function()
    {
    }
    this.Page = function()
    {
    }
    this.Select = function(selectId)
    {
    }
    this.ClearKey = function()
    {
    }
    this.Focus = function(revert)
    {
    }
}

function FileBrowseView(pickListCtrl)
{
    NamedObjectView.call(this, pickListCtrl);
    this.Select = function(selectId)
    {
        var node = igtree_getNodeById(selectId);
        if (node != null)
        {
            var value = node.getTag().split(top.PickListTagDelimiter)[0];
            tags = value.split(';');
            if(tags[0] == "True")
            {
                if(document.all[this.pickListControl.insiteCtrlId + "_Edit"].value != tags[2])
                {
                    document.all[this.pickListControl.insiteCtrlId + "_Edit"].value = tags[2];
                    document.all[this.pickListControl.insiteCtrlId + "_Edit"].fireEvent("onchange");
                }
                return true;
            }
        }
        return false;
    }
}

function NamedObjectView(pickListCtrl)
{
    ViewControlBase.call(this, pickListCtrl);

    this.Load = function()
    {
        return this.Refresh();
    }
    
    this.Filter = function()
    {
        return this.Refresh();
    }
    
    this.Page = function()
    {
        return this.Refresh();
    }
    
    this.Focus = function(revert)
    {
        var tree = igtree_getTreeById(this.pickListControl.viewCtrlId);
        if(revert)
            tree.setSelectedNode(null);
        else
        {
            if (tree != null)
                tree.Element.focus();
        }
    }

    this.Select = function(selectId)
    {
        var node = igtree_getNodeById(selectId);
        if (node != null)
        {
            var text = node.getText();
            var key = node.getDataKey();
            if (key == null)
                key = text;
            if (document.all[this.pickListControl.insiteCtrlId + "_Edit"].value != key ||
                document.all[this.pickListControl.insiteCtrlId + "_Value"].value != key)
            {
                document.all[this.pickListControl.insiteCtrlId + "_Edit"].value = key;
                document.all[this.pickListControl.insiteCtrlId + "_Value"].value = key;
                document.all[this.pickListControl.insiteCtrlId + "_Edit"].fireEvent("onchange");
            }
        }
        return true;
    }
    
    this.ClearKey = function()
    {
        document.all[this.pickListControl.insiteCtrlId + "_Value"].value = "";
    }

    this.Refresh = function()
    {
        var res = false;
        var tree = igtree_getTreeById(this.pickListControl.viewCtrlId);
        if (tree != null)
        {
            var root = tree.getNodeById(tree.Id + '_1');
            if (root != null)
            {
                if (!root.hasChildren())
                {
                    var dummy = root.insertChild(0, "");
                    dummy.setEnabled(false);
                    
                    //dummy.Element.style.display = "none";
                }
                    
                root.setPopulated(false)
                root.setExpanded(true);
                res = true;
            }
        }

        return res;
    }
    
    this.ToggleRootState = function(treeId, visible)
    {
        var tree = igtree_getTreeById(treeId);
        if (tree != null)
        {
            var root = tree.getNodeById(tree.Id + '_1');
            if (root != null)
            {
                if (visible)
                {
                    root.setExpanded(false);
                    root.Element.style.display = "block";
                }
                else
                {
                    root.Element.style.display = "none";
                }
            }
        }
    }
    
    this.BeforeDemanLoad = function(treeId, nodeId)
    {
        this.readyState = "loading";
    
        var node = igtree_getNodeById(nodeId);
        if (node.getText() == "root")
            this.ToggleRootState(treeId, true);
    }

    this.ProcessStatusTag = function(treeId, nodeId)
    {
        var pickList = getPickListByViewCtrlId(treeId);
        var node = igtree_getNodeById(nodeId);
        if (node != null && node.hasChildren())
        {
            var nodes = node.getChildNodes();
            if (nodes != null && nodes.length > 0)
            {
                var sysnode = nodes[nodes.length-1];
                if (sysnode.getTag() != null && sysnode.getTag().length > 0)
                {
                    var tag = sysnode.getTag().split(',');
                    if (tag[0] == "status")
                    {
                        //Status tag consists of number of pages, status message to display and number of the current page
                        if (parseInt(tag[1]) != 0)
                        {
                            pickList.SetPagesCount(tag[1]);
                            if (parseInt(tag[3]) != 0)
                            {
                                var pageCount = parseInt(tag[1]);
                                var currentPage = parseInt(tag[3]);
                                //Set pager buttons` styles according to the page position
                                if (currentPage == 1)
                                {
                                    this.pickListControl.SetPagerButtonDisable('Prev');
                                }//if
                                else if (currentPage == pageCount)
                                {
                                    this.pickListControl.SetPagerButtonDisable('Next');
                                }//else if
                                else if (currentPage > 1 && currentPage < pageCount)
                                {
                                    this.pickListControl.SetPagerButtonDisable('');
                                }//else if
                                document.getElementById(this.pickListControl.pagerCtrlId + "_Curp").value = currentPage;
                            }//if tag[3]
                        }// if tag[1]
                        if (tag[2].length > 0)
                        {
                            DisplayMessage(tag[2], false);
                        }//if tag[2]
                        node.removeChild(nodes.length-1);
                    }//if tag[0]
                }//if sysnode.getTag()
            }// if nodes
        }//if node
    }//ProcessStatusTag

    this.AfterDemandLoad = function(treeId, nodeId)
    {
        this.ProcessStatusTag(treeId, nodeId);

        var activeName;
        var activeRev;

        //Find text controls keeping name and revision values of the active instance, get these values and clear textboxes
        var instanceNameBox = document.getElementById(this.pickListControl.filterCtrlId + '_' + mkInstanceNameBox);
        var instanceRevBox = document.getElementById(this.pickListControl.filterCtrlId + '_' + mkInstanceRevBox);
        if (instanceNameBox != null)
        {
            activeName = instanceNameBox.value;
            instanceNameBox.value = "";
        }//if
        if (instanceRevBox != null)
        {
            activeRev = instanceRevBox.value;
            instanceRevBox.value = "";
        }//if

        var node = igtree_getNodeById(nodeId);

        if (node.getText() == "root")
        {
            this.ToggleRootState(treeId, false);
            if (activeName != "" && activeName != top.PickListTagDelimiter)
            {
                //Highlight node that is to be active
                HighlightNode(node, activeName, activeRev);
            }//if
        }//if
        this.readyState = "loaded";
    }//AfterDemandLoad

    this.newCallbackRender = function(payload, context)
    {
        var pickList = getPickListByViewCtrlId(context.clientId);
        if (pickList != null)
        {
            var viewCtrl = pickList.viewCtrl;
            var retCode = viewCtrl.oldCallbackRender(payload, context);
            viewCtrl.AfterDemandLoad(context.clientId, context.nodeId);
            return retCode;
        }//if
    }//newCallbackRender
}//NamedObjectView

///Finds a node that is to be active and highlights it
function HighlightNode(rootNode, name, rev)
{
    var selectionSet = false;
    var childNodes = rootNode.getChildNodes();
    //Loop through the nodes and find the active one
    for (var i=0; i<childNodes.length; i++)
    {
        if (!selectionSet)
        {
            //Loop through the child nodes if present
            if (childNodes[i].hasChildren() == true)
            {
                selectionSet = HighlightNode(childNodes[i], name, rev);
            }//if

            var tag = childNodes[i].getTag();
            if (tag != "")
            {
                var decodedTag = decodeURIComponent(tag);
                var components = decodedTag.split(top.PickListTagDelimiter);
                //0 and 1 components of the tag represent name and revision
                if (components[0] == name && components[1] == rev)
                {
                    childNodes[i].setSelected(true);
                    selectionSet = true;
                }//if
            }//if
        }//if
    }//for
    return selectionSet;
}//HighlightNode

function ContainerView(pickListCtrl)
{
    ViewControlBase.call(this, pickListCtrl);
    this.Load = function()
    {
        var res = false;
        var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
        if(g != null)
        {
            g.invokeXmlHttpRequest(g.eReqType.Filter, g.Bands[0].Columns[0], null);
            res = true;
        }
        return res;
    }
    this.Filter = function()
    {
        var res = false;
        var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
        if(g != null)
        {
            g.invokeXmlHttpRequest(g.eReqType.Filter, g.Bands[0].Columns[0], null);
            res = true;
        }
        return res;
    }
    this.Page = function()
    {
        var res = false;
        var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
        if(g != null)
        {
            g.invokeXmlHttpRequest(g.eReqType.Filter, g.Bands[0].Columns[0], null);
            res = true;
        }
        return res;
    }
    this.Select = function(selectId)
    {
        if (selectId != null)
        {
            var cell = igtbl_getRowById(selectId).getCellFromKey('Container');
            var value = '';
            if(cell != null)
                value = cell.getValue();
            if(document.all[this.pickListControl.insiteCtrlId + "_Edit"].value != value)
            {
                document.all[this.pickListControl.insiteCtrlId + "_Edit"].value = value;
                document.all[this.pickListControl.insiteCtrlId + "_Edit"].fireEvent("onchange");
            }
        }
        return true;
    }
    this.Focus = function(revert)
    {
        var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
        if(revert)
        {
            g.setActiveRow(null, true);
        }
        else
        {
            var row = g.getActiveRow();
            if(row == null)
                row = g.Rows.getRow(0);
            if(row != null)
            {
                g.setActiveRow(row, true);
                row.setSelected(true);
            }
        }
    }
}

function CarrierView(pickListCtrl)
{
    ViewControlBase.call(this, pickListCtrl);
    this.Load = function()
    {
        var res = false;
        var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
        if(g != null)
        {
            g.invokeXmlHttpRequest(g.eReqType.Filter, g.Bands[0].Columns[0], null);
            res = true;
        }
        return res;
    }
    this.Filter = function()
    {
        var res = false;
        var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
        if(g != null)
        {
            g.invokeXmlHttpRequest(g.eReqType.Filter, g.Bands[0].Columns[0], null);
            res = true;
        }
        return res;
    }
    this.Page = function()
    {
        var res = false;
        var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
        if(g != null)
        {
            g.invokeXmlHttpRequest(g.eReqType.Filter, g.Bands[0].Columns[0], null);
            res = true;
        }
        return res;
    }
    this.Select = function(selectId)
    {
        if (selectId != null)
        {
            var cell = igtbl_getRowById(selectId).getCellFromKey('CarrierName');
            if (cell == null) 
		        cell = igtbl_getRowById(selectId).getCellFromKey('Name');
            if (cell == null) 
		        cell = igtbl_getRowById(selectId).getCellFromKey('Carrier');
            var value = '';
            if(cell != null)
                value = cell.getValue();
            if (value == null)
                value = '';
            if(document.all[this.pickListControl.insiteCtrlId + "_Edit"].value != value)
            {
                document.all[this.pickListControl.insiteCtrlId + "_Edit"].value = value;
                document.all[this.pickListControl.insiteCtrlId + "_Value"].value = selectId;
                document.all[this.pickListControl.insiteCtrlId + "_Edit"].fireEvent("onchange");
            }
            else if (document.all[this.pickListControl.insiteCtrlId + "_Value"].value != selectId)
            {
                document.all[this.pickListControl.insiteCtrlId + "_Value"].value = selectId;
                document.all[this.pickListControl.insiteCtrlId + "_Value"].fireEvent("onchange");
            }
        }
        return true;
    }
    this.Focus = function(revert)
    {
        var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
        if(revert)
        {
            g.setActiveRow(null, true);
        }
        else
        {
            var row = g.getActiveRow();
            if(row == null)
                row = g.Rows.getRow(0);
            if(row != null)
            {
                g.setActiveRow(row, true);
                row.setSelected(true);
            }
        }
    }
}

function FileBrowseGridView(pickListCtrl)
{
    ContainerView.call(this, pickListCtrl);
    this.Select = function(selectId)
    {
            var path = document.getElementById(this.pickListControl.insiteCtrlId + '_Path');
            var g = igtbl_getGridById(this.pickListControl.viewCtrlId);
            var row = g.getActiveRow();
            if(row == null)
                row = igtbl_getCellById(g.ActiveCell).Row;
            var value = row.getCell(1).getValue();
            var type = row.getCell(2).getValue();
            var select = row.getCell(3).getValue().split(';')[0];
            if(value != '.' && value != '..' && select == 'True')
            {
                value = row.getCell(3).getValue().split(';')[1];
                if(document.all[this.pickListControl.insiteCtrlId + "_Edit"].value != value)
                {
                    document.all[this.pickListControl.insiteCtrlId + "_Edit"].value = value;
                    document.all[this.pickListControl.insiteCtrlId + "_Edit"].fireEvent("onchange");
                }
        }
        return true;
    }
}

// TreeViewControl client-side functions
// ---
function TreeViewControl_InitializeTree(treeId)
{
    var tree = igtree_getTreeById(treeId);
    var pickList = getPickListByViewCtrlId(treeId);

    // Handle callback fiinshing
    if(tree && pickList)
    {
        pickList.viewCtrl.oldCallbackRender = tree.callbackRender;
        tree.callbackRender = pickList.viewCtrl.newCallbackRender;
    }

    // Prepare root node
    if (tree != null)
    {
        var root = tree.getNodeById(tree.Id + '_1');
        if (root != null)
        {
            pickList.viewCtrl.ProcessStatusTag(treeId, tree.Id + '_1');
            root.Element.style.display = "none";
            if (root.getPopulated())
                root.setExpanded(true);
        }
    }
}

function TreeViewControl_DemandLoad(treeId, nodeId)
{
    var pickList = getPickListByViewCtrlId(treeId);
    if(pickList != null)
        pickList.viewCtrl.BeforeDemanLoad(treeId, nodeId);
}

function TreeViewControl_NodeClick(treeId, nodeId)
{
    var pickList = getPickListByViewCtrlId(treeId);
    if(pickList != null)
        pickList.Select(nodeId);
}
// -----------------------------------------------------------------------

function GridViewControl_InitializeLayout(gridId)
{
    var pickList = getPickListByViewCtrlId(gridId);
    var grid = igtbl_getGridById(gridId);
    var strs = grid.Bands[0].DataKeyField.split(';');
    grid.Bands[0].DataKeyField = '';
    if(strs[0] == '2')
        DisplayMessage(strs[1], false);
    else if(strs[0] == '1')
        pickList.SetPagesCount(strs[1]);
    if (grid != null)
    {
        var divElement = grid.getDivElement();
	if (divElement != null && divElement.parentElement != null && divElement.parentElement.style.height == "0px")
            divElement.parentElement.style.height = "100%";
    }
}
function GridViewControl_CellClick(gridId, cellId)
{
    var pickList = getPickListByViewCtrlId(gridId);
    if(pickList != null)
        pickList.Select(igtbl_getCellById(cellId).Row.Id);
}

function GridViewControl_KeyUp(gridId, rowId, key)
{
    if(key == '13')
    {
        var pickList = getPickListByViewCtrlId(gridId);
        if(pickList != null)
            pickList.Select(rowId);
    }
}

// ---

function GridViewControl_Response(gridId, rowId, xmlRespObj)
{
    if(xmlRespObj.ResponseStatus == 1)
        DisplayMessage(xmlRespObj.Tag, false);
    else
    {
        var pickList = getPickListByViewCtrlId(gridId);
        if(xmlRespObj.Tag != '')
            pickList.SetPagesCount(xmlRespObj.Tag);
    }
}

function FileBrowseGridViewControl_InitializeLayout(gridId)
{
    var pickList = getPickListByViewCtrlId(gridId);
    var ctrl = document.getElementById(pickList.insiteCtrlId + '_Panl');
    var table = document.createElement('table');
    var row = table.insertRow();
    var cell = row.insertCell();
    cell.style.height = '18px';
    table.style.width = ctrl.offsetWidth + 'px';
    cell.id = pickList.insiteCtrlId + '_Path';
    ctrl.insertBefore(table, ctrl.firstChild);
    var grid = igtbl_getGridById(gridId);
    var strs = grid.Bands[0].DataKeyField.split(';');
    grid.Bands[0].DataKeyField = '';
    if(strs[0] == '3')
    {
        cell.innerHTML = strs[1];
        FileBrowseGridViewControl_AfterResponse(gridId);
        strs[0] = '1';
        strs[1] = '1';
    }
    if(strs[0] == '2')
        DisplayMessage(strs[1], false);
    else if(strs[0] == '1')
        pickList.SetPagesCount(strs[1]);
    var row = grid.Rows.getRow(0);
    if(row != null)
    {
        grid.setActiveRow(row, true);
        row.setSelected(true);
    }
}

function FileBrowseGridViewControl_Response(gridId, rowId, xmlRespObj)
{
    if(xmlRespObj.ResponseStatus == 1)
        DisplayMessage(xmlRespObj.Tag, false);
    else
    {
        var grid = igtbl_getGridById(gridId);
        var pickList = getPickListByViewCtrlId(gridId);
        var path = document.getElementById(pickList.insiteCtrlId + '_Path');
        path.innerHTML = xmlRespObj.Tag;
        pickList.SetPagesCount('1');
        var row = grid.Rows.getRow(0);
        if(row != null)
        {
            grid.setActiveRow(row, true);
            row.setSelected(true);
        }
    }
}

function FileBrowseGridViewControl_KeyUp(gridId, rowId, key)
{
    if(key == '13')
    {
        selectoropen = 'select';
        if(event.ctrlKey)
            selectoropen = 'open';
        FileBrowseGridViewControl_Click(gridId);
    }
}

var selectoropen = 'select';
function FileBrowseGridViewControl_Click(gridId)
{
    var pickList = getPickListByViewCtrlId(gridId);
    var g = igtbl_getGridById(pickList.viewCtrlId);
    if(pickList != null)
    {
        if (selectoropen == 'select')
        {
            var row = g.getActiveRow();
            if(row == null)
                row = igtbl_getCellById(g.ActiveCell).Row;
            var value = row.getCell(2).getValue();
            var select = row.getCell(3).getValue().split(';')[0];
            if(value != '.' && value != '..' && select == 'True')
                pickList.Select(g.getActiveRow());
        }
        else
        {
            var path = document.getElementById(pickList.insiteCtrlId + '_Path');
            var row = g.getActiveRow();
            if(row == null)
                row = igtbl_getCellById(g.ActiveCell).Row;
            var value = row.getCell(1).getValue();
            var type = row.getCell(2).getValue();
            var select = row.getCell(3).getValue();
            if(type == 'Folder' || value == '.' || value == '..')
            {
                var col = g.Bands[0].Columns[0];
                var currentFilterString = g._getCurrentFiltersString(col,col.Band,'');
	            g.QueryString="Filter\x01" + col.getLevel(true) + "\x01" + path.innerHTML + value +"\x01" + "" + "\x01" + currentFilterString+"\x01"+g._buildSortOrder(g);
	            g.xmlHttpRequest(g.eReqType.Filter);
            }
        }
    }
    selectoropen = 'select';
}

function FileBrowseGridViewControl_CellClick(gridId, cellId)
{
    setTimeout('FileBrowseGridViewControl_Click("' + gridId + '");', 300);
}

function FileBrowseGridViewControl_DblClick(gridId, rowId)
{
    selectoropen = 'open';
}

function FileBrowseGridViewControl_AfterResponse(gridId)
{
    var grid = igtbl_getGridById(gridId);
    var row;
    for(var i = 0; i < grid.Rows.length; i++)
    {
        row = grid.Rows.getRow(i);
        var cel = row.getCell(0);
        cel.Element.style.backgroundRepeat = 'no-repeat';
    }
    var pickList = getPickListByViewCtrlId(gridId);
}
//---------------------------------------------------------------------
// RDO
//---------------------------------------------------------------------

function IsVisible(document, controlId)
{
    if(IsValidElement(document, controlId))
    {
        if (document.all[controlId].style.display == top.DisplayStyleNone)
        {
            return false;
        }//if
        else
        {
            return true;
        }//else
    }//if
    else
    {
        return false;
    }//if
}//IsVisible

function RevisionedObjectView(pickListCtrl)
{
    NamedObjectView.call(this, pickListCtrl);
    
    this.AfterDemandLoadBase = this.AfterDemandLoad;
    
    this.Select = function(selectId)
    {
        var node = igtree_getNodeById(selectId);
        if (node != null)
        {
            var encodedValue = node.getTag();
            var value = decodeURIComponent(encodedValue);
            var key = node.getDataKey();

            if (key != null && key != "")
                this.pickListControl.SetRDOValueWithDataKey(value, key);
            else
                this.pickListControl.SetRDOValue(value);
        }//if
        return true;
    }//Select

    this.AfterDemandLoad = function(treeId, nodeId)
    {
    window.attachEvent("onload", function() { setTimeout("var node = igtree_getNodeById('" + nodeId + "');if (node.hasChildren()){var nodes = node.getChildNodes();for (var i=0; i<nodes.length; i++){if (nodes[i].hasChildren() && nodes[i].getExpanded()){var expandNode=false; var children=nodes[i].getChildNodes();for(var j=0;j<children.length;j++){if (children[j].getSelected()){expandNode=true;}} nodes[i].setExpanded(expandNode);}}}", 10); })
        // This code is called in above statement. It collapses all web tree nodes.
        var node = igtree_getNodeById(nodeId);
        if (node.hasChildren())
        {
            var nodes = node.getChildNodes();
            for (var i=0; i<nodes.length; i++)
            {
                if (nodes[i].hasChildren() && nodes[i].getExpanded())
                    nodes[i].setExpanded(false);
            }//for
        }//if
        
        this.AfterDemandLoadBase(treeId, nodeId);
    }//AfterDemandLoad
}//RevisionedObjectView

function InitPickListControl(pickListCtrl, insiteCtrlId)
{
    pickLists[insiteCtrlId] = pickListCtrl;
}//InitPickListControl


function NamedObjectControl(insiteCtrlId, viewCtrlId, filterCtrlId, pagerCtrlId, needPostBack, typeAhead, dependentControls, viewCtrl)
{
    PickListControl.call(this, insiteCtrlId, viewCtrlId, filterCtrlId, pagerCtrlId, needPostBack, typeAhead, dependentControls, viewCtrl);
}//NamedObjectControl

function RevisionedObjectControl(insiteCtrlId, viewCtrlId, filterCtrlId, pagerCtrlId, needPostBack, typeAhead, dependentControls, viewCtrl)
{
    PickListControl.call(this, insiteCtrlId, viewCtrlId, filterCtrlId, pagerCtrlId, needPostBack, typeAhead, dependentControls, viewCtrl);
    
    this.nameFieldId = this.insiteCtrlId + "_Edit";
    this.revisionFieldId = this.insiteCtrlId + "_Rev";
    this.useRORFieldId = this.insiteCtrlId + "_UseROR";
    this.hiddenFieldId = this.insiteCtrlId + "_Hidden";
    this.ambientDivId = this.insiteCtrlId + "RevisionedDiv";
    this.pickListControlId = this.insiteCtrlId + "_Panl";
    
    //Set key into the hidden value field, invokes SetRDOValue to set name and revision
    this.SetRDOValueWithDataKey = function(value, key)
    {
        var needOnChange = false;
        var valueCtrl = document.getElementById(this.insiteCtrlId + "_Value");
        if (valueCtrl != null)
        {
            if (valueCtrl.value != key)
            {
                valueCtrl.value = key;
                needOnChange = true;
            }
        }

        if (!this.SetRDOValue(value) && needOnChange)
            document.all[this.hiddenFieldId].fireEvent("onchange");
    }
    
    //Set value into the name and revision fields, check ror field if necessary
    this.SetRDOValue = function(value)
    {
        var NameRevROR = new Array();
        NameRevROR = value.split(top.PickListTagDelimiter);

        var ControlFields = new Array(this.nameFieldId, this.revisionFieldId, this.useRORFieldId);
            
        if (AreValidElements(ControlFields))
        {
            var nameControl = gDoc[this.nameFieldId];
            var revControl = gDoc[this.revisionFieldId];
            var rorControl = gDoc[this.useRORFieldId];
        
            //Set value to the Name field
            nameControl.value = NameRevROR[0];
            //Clear revision control
            revControl.value = NameRevROR[1];

            //Presence of revision value determines whether ror is selected
            if (NameRevROR[1] != "")
        {
                NameRevROR[2] = 'false';
            }//if
            else
            {
                NameRevROR[2] = 'true';
            }//else

                if (NameRevROR[2] == 'true')
                {
                    if (!rorControl.checked)
                    {
                        rorControl.click();
                    }//if
                }//if
                else
                {
                    if (rorControl.checked)
                    {
                        rorControl.click();
                    }//if
                }//else

            NameRevROR[2] = rorControl.checked;
        
        var hiddenValue;
        hiddenValue = this.FormHiddenValue(NameRevROR);
        return this.SetRDOHiddenFieldValue(hiddenValue);
        }//if
    }//SetRDOValue
    
    //Forms a value for the hidden field
    this.FormHiddenValue = function(valueList)
    {
        var formedValue = "";
        for(var i=0; i<valueList.length; i++)
        {
            if (i < valueList.length - 1)
            {
                formedValue = formedValue + valueList[i] + top.PickListTagDelimiter;
            }//if
            else
            {
                formedValue = formedValue + valueList[i];
            }//else
        }//for
        return formedValue;
    }//FormHiddenValue
    
    //Set`s value into the RDO control`s hidden field, fires DataChanged event in case value differs from the previous
    this.SetRDOHiddenFieldValue = function (newValue)
    {
        if (IsValidElement(document, this.hiddenFieldId))
        {
            var hidden = gDoc[this.hiddenFieldId];
            var prevValue;
            prevValue = hidden.value;
            if (newValue != prevValue)
            {
                hidden.value = newValue;
                document.all[this.hiddenFieldId].fireEvent("onchange");
                return true;
            }//if
        }//if
    }//SetRDOHiddenFieldValue
    
    //Handles div`s ondeactivate event.
    //Checks if focus is not on the div or it`s child controls.
    //Gathers RDO control`s data and checks if it was changed, fires DataChanged event in this case.
    this.FireDataChanged = function()
    {
        if (this.IsRDODataChangeFinished())
        {
            if (!IsVisible(document, this.pickListControlId))
            {
                var ControlFields = new Array(this.nameFieldId, this.revisionFieldId, this.useRORFieldId);
                if (AreValidElements(ControlFields))
                {
                    var NameRevROR = new Array(gDoc[this.nameFieldId].value, gDoc[this.revisionFieldId].value, gDoc[this.useRORFieldId].checked);
                    var hiddenValue;
                    hiddenValue = this.FormHiddenValue(NameRevROR);

                    this.SetRDOHiddenFieldValue(hiddenValue);
                }//if
            }//if
        }//if
    }//FireDataChanged
    
    //Checks if any of the child controls of the ambient div is in focus
    this.IsRDODataChangeFinished = function()
    {
        if (document != null)
        {
            if (document.activeElement != null)
            {
                var active = document.activeElement;
                var ambientDiv = gDoc[this.ambientDivId];
                if (IsElementChildOf(active, ambientDiv))
                {
                    return false;
                }//if
                else { return true; }//else
            }//if
            else { return true; }//else
        }//if
        else { return true; }//else
    }//IsRDODataChangeFinished
    
    //Handles checkbox`s onclick event
    this.RDOUseRORClick = function()
    {
        if (IsValidElement(document, this.revisionFieldId) && IsValidElement(document, this.useRORFieldId))
        {
            var revisionControl = gDoc[this.revisionFieldId];
            var useRORControl = gDoc[this.useRORFieldId];
            var parentSpan = useRORControl.parentElement;
            
            if (useRORControl.checked)
            {
                if (parentSpan.style.display != 'none')
                {
                    //RDOFormat==Standard
                    revisionControl.value = "";
                    revisionControl.style.backgroundColor = 'gray';
                    revisionControl.readOnly = true;
                }//if
            }//if
            else
            {
                revisionControl.style.removeAttribute('backgroundColor');
                revisionControl.readOnly = false;
            }//else
        }//if
    }//RDOUseRORClick
}//RevisionedObjectControl

//Allows selecting only for the leaf nodes for the case when RDO control is in the RDOFormat=Revision
function RDO_NodeClick(treeId, nodeId)
{
    var node = igtree_getNodeById(nodeId);
    if (node != null)
    {
        var tree = node.getTreeId();
        var button = igtree_getNodeExpandCollapseImage(tree, node);
        //PostBack occurs only for the leafs of the tree
        if (button == null)
        {
            TreeViewControl_NodeClick(treeId, nodeId)
        }//if
    }//if
}//RDO_NodeClick

//Get selected node`s tag, decode it and call LoadInstance to load corresponding form and instance
//A Tag consists of :
// 0 - instance name,
// 1 - instance revision,
// 2 - instance is ROR,
// 3 - page address,
// 4 - service type,
// 5 - help page address;
function FrameworkInstanceList_NodeClick(treeId, nodeId)
{
    var node = igtree_getNodeById(nodeId);
    if (node != null)
    {
        var tagValue = node.getTag();
        var tagDecoded = decodeURIComponent(tagValue)
        var parametersArray = new Array();
        parametersArray = tagDecoded.split(top.PickListTagDelimiter);

        LoadInstance('', parametersArray[3], parametersArray[0], parametersArray[1], parametersArray[2], parametersArray[4], parametersArray[5])
    }//if
}//FrameworkInstanceList_NodeClick

//--------------------------------------------------------------------------------------------------------------------------
//Workflow Navigator
//--------------------------------------------------------------------------------------------------------------------------

function WorkflowNavigatorView(pickListCtrl)
{
    RevisionedObjectView.call(this, pickListCtrl);

    this.Select = function(selectId)
    {
        var node = igtree_getNodeById(selectId);
        if (node != null)
        {
            var tree = node.getTreeId();
            var button = igtree_getNodeExpandCollapseImage(tree, node);
            //Select leafs only
            if (button == null)
            {
                var encodedValue = node.getTag();
                var value = decodeURIComponent(encodedValue);
                var path = node.getDataPath();
                value = value + top.PickListTagDelimiter + path;
                this.pickListControl.SetNavigatorValue(value)
                return true;
            }//if
        }//if
        return false;
    }//Select
}//WorkflowNavigatorView

function WorkflowNavigatorControl(insiteCtrlId, viewCtrlId, filterCtrlId, pagerCtrlId, needPostBack, typeAhead, dependentControls, viewCtrl)
{
    RevisionedObjectControl.call(this, insiteCtrlId, viewCtrlId, filterCtrlId, pagerCtrlId, needPostBack, typeAhead, dependentControls, viewCtrl);
    
    this.stepFieldId = this.insiteCtrlId + "_Step_Edit";
    
    //Set values into the name, revision and step fields, check ror field if necessary
    this.SetNavigatorValue = function(value)
    {
        var NameRevRORStep = new Array();
        NameRevRORStep = value.split(top.PickListTagDelimiter);

        var ControlFields = new Array(this.nameFieldId, this.revisionFieldId, this.useRORFieldId, this.stepFieldId);
            
        if (AreValidElements(ControlFields))
        {
            var nameControl = gDoc[this.nameFieldId];
            var revControl = gDoc[this.revisionFieldId];
            var rorControl = gDoc[this.useRORFieldId];
            var stepControl = gDoc[this.stepFieldId];

            //Set value to the Name field
            nameControl.value = NameRevRORStep[0];
            //Clear revision control
            revControl.value = NameRevRORStep[1];
            //Set value to the Step field
            stepControl.value = NameRevRORStep[3];
        
            //Presence of revision value determines whether ror is selected
            if (NameRevRORStep[1] != "")
        {
                NameRevRORStep[2] = 'false';
            }//if
            else
            {
                NameRevRORStep[2] = 'true';
            }//else

                if (NameRevRORStep[2] == 'true')
                {
                    if (!rorControl.checked)
                    {
                        rorControl.click();
                    }//if
                }//if
                else
                {
                    if (rorControl.checked)
                    {
                        rorControl.click();
                    }//if
                }//else

            NameRevRORStep[2] = rorControl.checked;
        
        var hiddenValue;
        hiddenValue = this.FormHiddenValue(NameRevRORStep);
        this.SetRDOHiddenFieldValue(hiddenValue);
        }//if
    }//SetRDOValue

    //Handles checkbox`s onclick event
    this.RDOUseRORClick = function()
    {
        if (IsValidElement(document, this.revisionFieldId) && IsValidElement(document, this.useRORFieldId))
        {
            var revisionControl = gDoc[this.revisionFieldId];
            var useRORControl = gDoc[this.useRORFieldId];
            var parentSpan = useRORControl.parentElement;

            if (useRORControl.checked)
            {
                if (revisionControl.value == "")
                {
                revisionControl.style.backgroundColor = 'gray';
            }//if
            else
            {
                revisionControl.style.removeAttribute('backgroundColor');
                }//else
            }//if
            else
            {
                revisionControl.style.removeAttribute('backgroundColor');
            }//else
        }//if
    }//RDOUseRORClick
}//WorkflowNavigatorControl

//Allows sending NodeClicked event only for the leaf nodes
function WorkflowNavigator_NodeClick(treeId, nodeId)
{
    var node = igtree_getNodeById(nodeId);
    if (node != null)
    {
        var tree = node.getTreeId();
        
        var button = igtree_getNodeExpandCollapseImage(tree, node);
        var nodeTag	= node.getTag();

        //PostBack occurs only for the leafs of the tree. Leafs have 4 data cells.
        if (nodeTag.split("%C3%BF").length == 3)
            return true;
        else
            TreeViewControl_NodeClick(treeId, nodeId)
    }//if
    return false;
}//WorkflowNavigator_NodeClick

//Checks if all the reported elements are valid
function AreValidElements(valueList)
{
    var isValidList = true;
    for(var i=0; i<valueList.length; i++)
    {
        if (isValidList == true)
        {
            if (!IsValidElement(document, valueList[i]))
            {
                isValidList = false;
            }//if
        }//if
    }//for
    return isValidList;
}//AreValidElements


// DropDownList client-side support classes
// DropDownList control class
function DropDownListControl(insiteCtrlId, viewCtrlId, filterCtrlId, pagerCtrlId, needPostBack, typeAhead, dependentControls, viewCtrl)
{
    NamedObjectControl.call(this, insiteCtrlId, viewCtrlId, filterCtrlId, pagerCtrlId, needPostBack, typeAhead, dependentControls, viewCtrl);

    this.SelectManual = function(value)    
    {
        var res = this.viewCtrl.SelectManual(value);
        return this.needPostBack;
    }
} // DropDownListControl

// DropDownList view control class
function DropDownListView(pickListCtrl)
{
    NamedObjectView.call(this, pickListCtrl);

    this.Select = function(selectId)
    {
        var node = igtree_getNodeById(selectId);
        if (node != null)
        {
            var value = node.getText();
            if (document.all[this.pickListControl.insiteCtrlId + "_Edit"].value != value)
            {
                document.all[this.pickListControl.insiteCtrlId + "_Edit"].value = value;
                document.all[this.pickListControl.insiteCtrlId + "_List_Value"].value = node.getDataKey();
                document.all[this.pickListControl.insiteCtrlId + "_Edit"].fireEvent("onchange");
            }
        }
        return true;
    } // Select
    
    this.SelectManual = function(text)
    {
        var editCtrl = document.all[this.pickListControl.insiteCtrlId + "_Edit"];
        var selectCtrl = document.all[this.pickListControl.insiteCtrlId + "_List_Value"];

        if (selectCtrl != null && editCtrl != null)
        {
            var options = selectCtrl.getElementsByTagName("option");
            if (options != null)
            {
                var isTextValid = false;
                
                for (var i=0; i<options.length; i++)
                {
                    var optionText = options[i].text;
                    if (optionText == null)
                        optionText = "";
                    if (text == null)
                        text = "";
                        
                    if (options[i].attributes['selected'].value == 'true')
                    {
                        selectCtrl.value = options[i].value;
                        editCtrl.value = options[i].text;
                        isTextValid = true;
                        break;
                    }
                }       
                    
                if (!isTextValid)
                    selectCtrl.value = "";
            }
        }
    } // SelectManual
} // DropDownListView

//Allows node click only for the nodes representing not abstract types
function CDOTypes_NodeClick(treeId, nodeId)
{
    var node = igtree_getNodeById(nodeId);
    if (node != null)
    {
        //Tag contains "true" in case type is abstract otherwise "false"
        var tagValue = node.getTag();
        if (tagValue == "false")
        {
            TreeViewControl_NodeClick(treeId, nodeId)
        }//if
    }//if
}//CDOTypes_NodeClick

//Allows selecting only for the leaf nodes
function ChargeToStep_NodeClick(treeId, nodeId)
{
    var node = igtree_getNodeById(nodeId);
    if (node != null)
    {
        var tree = node.getTreeId();
        var button = igtree_getNodeExpandCollapseImage(tree, node);
        if (button == null)
        {
            TreeViewControl_NodeClick(treeId, nodeId)
        }//if
    }//if
}//ChargeToStep_NodeClick

//Creates standard browse dialog box and sets input parameter value to filename picked by user 
function GetLocalFileName(ctrlId)
{
    var hiddenFileInput = document.createElement("input");
    hiddenFileInput.type = "file";
    document.appendChild(hiddenFileInput);

    var textControl = document.getElementById(ctrlId);

    hiddenFileInput.click();
    if (hiddenFileInput.value != "" && textControl != null)
        textControl.value = hiddenFileInput.value;

    document.removeChild(hiddenFileInput);

    return false;
}//GetLocalFileName
